define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'daikuan/index' + location.search,
                    add_url: 'daikuan/add',
                    edit_url: 'daikuan/edit',
                    del_url: 'daikuan/del',
                    multi_url: 'daikuan/multi',
                    import_url: 'daikuan/import',
                    table: 'daikuan',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'uid', title: __('Uid'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'arrayt_t', title: __('Arrayt_t'), operate: 'LIKE'},
                        {field: 'total', title: __('Total'), operate:'BETWEEN'},
                        {field: 'monthly', title: __('Monthly'), operate:'BETWEEN'},
                        {field: 'time', title: __('Time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'desc', title: __('Desc'), operate: 'LIKE'},
                        {field: 'simage', title: __('Simage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'wimage', title: __('Wimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'cpname', title: __('Cpname'), operate: 'LIKE'},
                        {field: 'cptype', title: __('Cptype'), operate: 'LIKE'},
                        {field: 'cpphone', title: __('Cpphone'), operate: 'LIKE'},
                        {field: 'cpadd', title: __('Cpadd'), operate: 'LIKE'},
                        {field: 'cptime', title: __('Cptime'), operate: 'LIKE'},
                        {field: 'cpwork', title: __('Cpwork'), operate: 'LIKE'},
                        {field: 'sosname', title: __('Sosname'), operate: 'LIKE'},
                        {field: 'sosmobile', title: __('Sosmobile'), operate: 'LIKE'},
                        {field: 'bank', title: __('Bank'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'sosname1', title: __('Sosname1'), operate: 'LIKE'},
                        {field: 'sosmobile1', title: __('Sosmobile1'), operate: 'LIKE'},
                        {field: 'sosname2', title: __('Sosname2'), operate: 'LIKE'},
                        {field: 'sosmobile2', title: __('Sosmobile2'), operate: 'LIKE'},
                        {field: 'sosname3', title: __('Sosname3'), operate: 'LIKE'},
                        {field: 'sosmobile3', title: __('Sosmobile3'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
